package com.chen.blog.service.impl;

import com.chen.blog.mapper.UserMapper;
import com.chen.blog.pojo.User;
import com.chen.blog.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author cgj
 * @date 1/20/25 6:58 PM
 */
@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    @Transactional(readOnly = true)
    public User login(User user) {
        User loginUser = userMapper.selectUserByUsername(user);
//      先看查没查到
        if(loginUser!=null){
            if(loginUser.getPassword().equals(user.getPassword())){
                return  loginUser;
            }
        }
        return null;
    }

    @Override
    @Transactional(readOnly = true)
    public User getUserByUid(Integer uid) {
        return userMapper.selectUserByUserUid(uid);
    }

    @Override
    public Integer changeUserInfo(User user) {
        return userMapper.updateUser(user);
    }
}
